/**
 * 具体的资源池信息
 */
$(function () {

    var initCurrPage =  1;
    var initPageSize =  5;
    var paginationFlag =  false;
    searchData();

    $(".news").on('mouseenter', function(){
        $(this).addClass("shadow");
    });

    $(".news").on('mouseleave', function(){
        $(this).removeClass("shadow");
    });

    function link() {
        window.location.href="activity_info.html";
    }



    // 查询数据
    function searchData(paramData) {
        if (!paramData) {
            paramData = {};
        }
        paramData.loadAll = false;
        paramData.needPaging = true;
        paramData.currPage = paramData.currentPage ? paramData.currentPage : initCurrPage;
        paramData.pageSize = paramData.pageSize ? paramData.pageSize : initPageSize;

        let params = {
            url:  "/index/exchanges",
            data: paramData,
            sCallback: function (data) {
                searchDataSuccessCallback(data);
            },
            eCallback: function (res) {
            }
        }
        requset(params);
    }

    /**
     * 分页查询之后的成功回调
     * @param data
     */
    function searchDataSuccessCallback(data) {
        var total = data.total;
        var pageSize = data.pageSize;
        let paginationParams = {total: total, pageSize: pageSize};
        if (!paginationFlag) {
            paginationFlag = true;
            paginationInit(paginationParams, changePagination);
        }
        // 设置数据
        var htmlCode = "";
        var idArray = [];
        $.each(data.rows, function (index, dataMap) {
            // 获取真实数据 {id: "305305a0-b701-11e8-8bb3-00163e0280a5", status: 1, name: "我是一家企业", country: "天津市,天津市区,和平区", reqName: "这是一个需求测试", …}
            var id = dataMap['id'];//id
            var title = dataMap['title'];
            var enroll_start = dataMap['enroll_start'];//报名时间
            var ex_start = dataMap['exStart'];//活动开始时间
            var start = datetimeFormatLong2String(ex_start);
            var ex_end = dataMap['exEnd'];
            var end = datetimeFormatLong2String(ex_end);
            var organizer_name = dataMap['organizerName'];
            var ex_addr = dataMap['exAddr'];
            var subject = dataMap['subject'];
            var cover = imageUrl+dataMap['cover'];
            var classType = "tips_bm";
            var classTip = dataMap['exStatus'];
            idArray.push(id);
            if( classTip == "未开始"){
                classType = "tips_unstart";
            }
            if( classTip == "报名中"){
                classType = "tips_bm";
            }
            if( classTip == "进行中"){
                classType = "tips_start";
            }
            if( classTip == "已结束"){
                classType = "tips_end";
            }
            if( classTip == "即将开始"){
                classType = "tips_onstart";
            }
            if( classTip == "进行中,可报名"){
                classType = "tips_canbm";
            }
            if(title.indexOf('\n') >=0){ title = title.replace(/\n/g,"");}
            htmlCode+="<div class='news wow fadeInUp' id="+id+" exStatus="+classTip+">"+
                "<img src="+cover+"><div class='con'><div class='con_title'>"+
                "<a href='javascript:void(0)'>"+title+"</a><span style='text-align:center' class="+classType+">"+classTip+"</span></div><span>"+
                "起止时间： "+start+" 至 "+end+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;活动主办方："+organizer_name+
                "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
                "活动地点："+ex_addr+"</span><div class='small_font'>主题："+subject+"</div></div><div class='clearfix'></div></div>";
        });
        $("#contentarea").html(htmlCode);
        itemClickRegister(idArray)
    }

    /**
     * 分页组件发生改变之后回调
     * @param paginationParams
     */
    function changePagination(paginationParams) {
        paginationParamsFinal = paginationParams
        searchData(paginationParams)
    }

    function itemClickRegister(idArray) {
        $.each(idArray, function (index, value) {
            var exStatus = $('#' + value).attr("exStatus");
            $('#' + value).on('click', function () {
                var url = encodeURI("info.html?id=" + value +"&type=TZGGHDTZ&exStatus="+exStatus);
                window.location.href = url;
            })
        })
    }


});


